﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for AccountBus
/// </summary>
public class AccountBus
{
    AccountDAL accDAL;
	public AccountBus()
	{
        accDAL = new AccountDAL();
    }
    public bool Checklogin(string UserName, string passWord)
    {
        DataTable dt = accDAL.Login(UserName, passWord);
        if (dt.Rows.Count > 0)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    public string InsertUpdateAccount(Account acc)
    {
        if (accDAL.InsertUpdateAccount(acc) != 0) 
        {
            return "Add Account Successful";
        }
        else
        {
            return "Add Fail";
        }
    }
    public Account GetAccountByUserName(string username) 
    {
        DataTable dt = new DataTable();
        dt = accDAL.getAccountByUserName(username);
        Account acc = new Account();
        acc.User_id = Convert.ToInt32(dt.Rows[0][0].ToString());
        acc.Username = dt.Rows[0][1].ToString();
        acc.Password = dt.Rows[0][2].ToString();
        acc.User_group_id = Convert.ToInt32(dt.Rows[0][3].ToString());
        acc.Email = dt.Rows[0][4].ToString();
        acc.First_name = dt.Rows[0][5].ToString();
        acc.Last_name = dt.Rows[0][6].ToString();
        acc.Phone = dt.Rows[0][7].ToString();
        acc.Status = dt.Rows[0][8].ToString();
        acc.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        acc.User_group_name = dt.Rows[0]["user_group_name"].ToString();
        acc.Permission = dt.Rows[0]["permission"].ToString();
        return acc;
    }
    public Account GetAccountByID(int user_id) 
    {

        DataTable dt = new DataTable();
        dt = accDAL.getAccountByID(user_id);
        Account acc = new Account();
        acc.User_id = Convert.ToInt32(dt.Rows[0][0].ToString());
        acc.Username = dt.Rows[0][1].ToString();
        acc.Password = dt.Rows[0][2].ToString();
        acc.User_group_id = Convert.ToInt32(dt.Rows[0][3].ToString());
        acc.Email = dt.Rows[0][4].ToString();
        acc.First_name = dt.Rows[0][5].ToString();
        acc.Last_name = dt.Rows[0][6].ToString();
        acc.Phone = dt.Rows[0][7].ToString();
        acc.Status = dt.Rows[0][8].ToString();
        acc.Date_added = Convert.ToDateTime(dt.Rows[0][9].ToString());
        return acc;
    }
    public DataTable getAllAccount()
    {
        return accDAL.getAccountAll();
    }
}
